package com.arceus.leetcode;

/**
 * @author : iron
 * @version : 1.0.0
 * @date : 11:28 AM 2019/3/1
 */

public class T953 {
    public static boolean isAlienSorted(String[] words, String order) {

        for (int i = 0; i < words.length - 1; i++) {
            char[] c1 = words[i].toCharArray();
            char[] c2 = words[i + 1].toCharArray();
            int count = 0;

            int length = c1.length > c2.length ? c2.length : c1.length;
            for (int l = 0; l < length; l++) {
                if (order.indexOf(c1[l]) == order.indexOf(c2[l])) {
                    count++;
                    continue;
                }
                if (count ==l && order.indexOf(c1[l]) > order.indexOf(c2[l])) {
                    return false;
                }
            }
            if (count == length && c1.length > c2.length) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(isAlienSorted(new String[]{"hello", "leetcode"}, "hlabcdefgijkmnopqrstuvwxyz"));
    }
}
